package org.example.osproject01.Object;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;

public class LineChartUtils
{
    private LineChart lineChart;
    XYChart.Series<String, Number> series1 = new XYChart.Series<>();
    public LineChartUtils(LineChart lineChart)
    {
        this.lineChart = lineChart;
        operateLineChart();
    }
    void operateLineChart()
    {
        //声明两条轴
        final CategoryAxis xAxis = (CategoryAxis) lineChart.getXAxis();
        final NumberAxis yAxis = (NumberAxis) lineChart.getYAxis();
        //定义轴的名称
        xAxis.setLabel("时间段");
        yAxis.setLabel("进程");
        yAxis.setAnimated(true);
        //显示图表
        lineChart.getData().addAll(series1);
    }
    public void addData(String month, int value) {
        series1.getData().add(new XYChart.Data<>(month, value));
    }
}

